package com.helloae;

import java.io.IOException;
import java.net.UnknownHostException;

import com.esri.arcgis.datasourcesGDB.Sde4Workspace;
import com.esri.arcgis.datasourcesGDB.SdeWorkspaceFactory;
import com.esri.arcgis.geodatabase.esriDatasetType;
import com.esri.arcgis.system.AoInitialize;
import com.esri.arcgis.system.EngineInitializer;
import com.esri.arcgis.system.PropertySet;
import com.esri.arcgis.system.esriLicenseProductCode;

/**
 * 判断ArcSDE中是否有某个图层
 * @author zhushijie
 *
 */
public class DataIsExistInSDE {

	public static void main(String[] args) throws UnknownHostException, IOException {
		// 初始化AE许可
		EngineInitializer.initializeEngine();
		AoInitialize ao = new AoInitialize();
		ao.initialize(esriLicenseProductCode.esriLicenseProductCodeArcEditor);
		
		SdeWorkspaceFactory sdeFactory = new SdeWorkspaceFactory();
		
		//ArcSDE的连接信息
		PropertySet prop = new PropertySet();
		prop.setProperty("SERVER", "192.168.3.106");
		prop.setProperty("INSTANCE", "5151");
		prop.setProperty("DATABASE", "sde");
		prop.setProperty("USER", "mysde");
		prop.setProperty("PASSWORD", "mysde");
		prop.setProperty("VERSION", "SDE.DEFAULT");
		
		Sde4Workspace sdeWS = new Sde4Workspace( sdeFactory.open(prop, 0));
		System.out.println(sdeWS.isNameExists(esriDatasetType.esriDTFeatureClass, "soils"));
		System.out.println(sdeWS.isNameExists(esriDatasetType.esriDTFeatureClass, "idcounty"));
		
		sdeWS.release();
		sdeFactory.release();
		ao.shutdown();
		System.out.println("Congratulaction!");
	}

}
